import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../home/model/comic_category_item_model.dart';

// 在 ManhListItem 构造函数中添加 comic 参数
class ManhListItem extends StatelessWidget {
  final ComicItemModel? comic;

  const ManhListItem({
    super.key,
    this.comic,
  });

  @override
  Widget build(BuildContext context) {
    // 使用 comic 数据渲染 UI
    return GestureDetector(
      onTap: () => {
        // GoRouter.of(context).push('/home_detail/${comic?.id}')
        // 直接跳转到漫画阅读页面
        if (comic?.id != null)
          {
            context.pushNamed(
              'direct_reader',
              pathParameters: {
                'chapterId': comic?.id ?? '',
                'comicId': comic?.id ?? '',
              },
            )
          }
      },
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 漫画封面
          ClipRRect(
            borderRadius: BorderRadius.circular(6),
            child: CachedNetworkImage(
              width: 80,
              height: 120,
              imageUrl: comic?.cover ?? '',
              fit: BoxFit.cover,
              placeholder: (context, url) => Container(
                color: const Color(0xFF2A1F3D), // 占位符背景色
              ),
              errorWidget: (context, url, error) => Container(
                color: const Color(0xFF2A1F3D),
                child: const Icon(
                  Icons.error,
                  color: Color(0xFF8B7AA8),
                ),
              ),
            ),
          ),
          const SizedBox(width: 12),
          // 漫画标题等信息
          Flexible(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                Text(
                  comic?.title ?? "",
                  style: const TextStyle(
                    color: Colors.white,
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                  ),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
                const SizedBox(height: 4),
                Text(
                  comic?.desc ?? "", // 这里也可以根据实际是其他内容，比如作者等，示例重复标题
                  style: const TextStyle(
                    color: Colors.white54,
                    fontSize: 12,
                  ),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
